package com.cskaoyan.com.collection.blockingqueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class DemoBlockingQueue2 {
    public static void main(String[] args) throws InterruptedException {

        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(2);

        blockingQueue.offer("zs");
        blockingQueue.offer("ls");

        MyThread myThread = new MyThread(blockingQueue);
        myThread.start();

        blockingQueue.put("wu");

        System.out.println(blockingQueue);
    }
}
class MyThread extends Thread{
    BlockingQueue blockingQueue;
    public MyThread(BlockingQueue blockingQueue){
        this.blockingQueue = blockingQueue;
    }

    public void run(){
        //
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        Object poll = blockingQueue.poll();
        System.out.println(poll);
    }
}
